package cn.webestar.scms.user.api.dto.Department;

import cn.webestar.scms.commons.api.SimpleBody;
import cn.webestar.scms.user.entity.Department;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.util.StringUtils;

import java.util.Date;

@Data
@Schema(description = "DepartmentSimpleDTO")
public class DepartmentSimpleDTO extends SimpleBody {

    @Schema(description = "租户id")
    private Long cid;

    @Schema(description = "父部门")
    private Long pid;

    @Schema(description = "排序号")
    private Integer sort;

    @Schema(description = "部门编码")
    private String no;

    @Schema(description = "部门名称")
    private String name;

    @Schema(description = "创建人")
    private Long creator;

    @Schema(description = "更新人")
    private Long updater;

    @Schema(description = "创建时间")
    private Date createTime;

    @Schema(description = "更新时间")
    private Date updateTime;

    @Schema(description = "状态，0：禁用，1：启用")
    private Integer status;

    @Schema(description = "备注")
    private String remark;

    @Override
    public LambdaQueryWrapper<Department> toQueryWapper() {
        LambdaQueryWrapper<Department> queryWrapper = new LambdaQueryWrapper<>();
        if (cid!=null) {
            queryWrapper.eq(Department::getCid, cid);
        }
        if (pid!=null) {
            queryWrapper.eq(Department::getPid, pid);
        }
        if (sort!=null) {
            queryWrapper.eq(Department::getSort, sort);
        }
        if (StringUtils.hasText(no)) {
            queryWrapper.eq(Department::getNo, no);
        }
        if (StringUtils.hasText(name)) {
            queryWrapper.eq(Department::getName, name);
        }
        if (creator!=null) {
            queryWrapper.eq(Department::getCreator, creator);
        }
        if (updater!=null) {
            queryWrapper.eq(Department::getUpdater, updater);
        }
        if (createTime!=null) {
            queryWrapper.eq(Department::getCreateTime, createTime);
        }
        if (updateTime!=null) {
            queryWrapper.eq(Department::getUpdateTime, updateTime);
        }
        if (status!=null) {
            queryWrapper.eq(Department::getStatus, status);
        }
        return queryWrapper;
    }

}
